package com.hzhr.iot.cqgas.ds.controller;

import com.hzhr.iot.core.util.HzhrDateUtil;
import com.hzhr.iot.cqgas.ds.dao.device.example.DevIotDeviceDao;
import com.hzhr.iot.cqgas.ds.entity.device.DevIotDeviceEntity;
import com.hzhr.iot.cqgas.ds.entity.device.DevIotDeviceExample;
import com.hzhr.iot.cqgas.ds.service.IotDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class IotDeviceController {
    @Autowired
    IotDeviceService iotDeviceService;
    @Autowired
    DevIotDeviceDao devIotDeviceDao;

    @RequestMapping(value = "/syncIotDevice")
    public void syncIotDevice() {
        DevIotDeviceEntity devIotDeviceEntity = new DevIotDeviceEntity();
        devIotDeviceEntity.setState("3");
        DevIotDeviceExample devIotDeviceExample = new DevIotDeviceExample();
        devIotDeviceExample.createCriteria().andOutIdIsNotNull();
        devIotDeviceDao.updateByExampleSelective(devIotDeviceEntity, devIotDeviceExample);

        iotDeviceService.syncIotDevice(null, null);

        devIotDeviceExample = new DevIotDeviceExample();
        devIotDeviceExample.createCriteria().andStateEqualTo("3");
        devIotDeviceDao.deleteByExample(devIotDeviceExample);
    }

    @RequestMapping(value = "/syncIotDevice_day")
    public void syncIotDevice_day() {
        DevIotDeviceEntity devIotDeviceEntity = new DevIotDeviceEntity();
        devIotDeviceEntity.setState("3");
        DevIotDeviceExample devIotDeviceExample = new DevIotDeviceExample();
        devIotDeviceExample.createCriteria().andOutIdIsNotNull();
        devIotDeviceDao.updateByExampleSelective(devIotDeviceEntity, devIotDeviceExample);

        iotDeviceService.syncIotDevice(HzhrDateUtil.getDayBegin(), null);

        devIotDeviceExample = new DevIotDeviceExample();
        devIotDeviceExample.createCriteria().andStateEqualTo("3");
        devIotDeviceDao.deleteByExample(devIotDeviceExample);
    }
}
